// TOWN SCRIPT
//    Town 0: Poulan

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k,lvl,choice;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
//Names
	set_name(6,"Council");
	set_name(7,"Council");
	set_name(8,"Council");
	set_name(9,"Kev");
	set_name(10,"Mayor Key");
	set_char_dialogue_pic(10,1974,0);
	set_name(11,"Commander Scott");
	set_name(12,"Harry");
	set_name(13,"Milhous");
	set_name(14,"Erin");
	set_name(15,"Baby");
	set_name(20,"Becky");
	set_name(21,"Colleen");
	set_name(22,"Anna");
	set_char_dialogue_pic(22,1972,0);
	set_name(23,"Holmes");
	set_name(24,"Chris");
	set_name(25,"Ramiro");
	set_name(26,"Bianca");
	set_name(27,"Brian");
	set_name(28,"Jennifer");
	set_name(29,"Ryan");
	set_name(30,"Mike");
	set_name(31,"Brendan");

	set_crime_tolerance(5);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;

	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(13,"Zzzz...");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(20,"This isn't good at all...");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(21,"Ugh... shut up, Becky.");

break;

beginstate 10;//leave
	reset_dialog();
	add_dialog_str(0,"Are you ready to leave the scenario?",0);
	add_dialog_choice(0,"Not yet.");
	add_dialog_choice(1,"Yes, I'm done here.");
	choice = run_dialog(1);
	if (choice == 1)
		block_entry(1);
	if (choice == 2)
		set_state_continue(11);
break;

beginstate 11;//exit scen
	if (get_flag(200,5) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"You leave the valley. It's a shame you couldn't help the citizens of this area, but there probably wasn't anything you could do anyway. Perhaps someone else will save the valley before it's too late.",0);
		add_dialog_str(1,"In any case, it's not your problem. You live to keep adventuring. It wouldn't have helped them at all if you'd gone against the dragon and died, now would it?",0);
		choice = run_dialog(0);
		end_scenario(0);
	}
	else {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"You walk out the south gates with a sense of satisfaction. You have saved this valley from complete destruction by the dragon. Perhaps in time, all that it was can be restored.",0);
		add_dialog_str(1,"But this quest has revealed a new truth the world: the dragons aren't all gone. There could be many more anywhere and everywhere. Hopefully, any other survivors of the Empire's dragon genocide will be more forgiving of the human race.",0);
		add_dialog_str(2,"THE END",0);
		choice = run_dialog(0);
		end_scenario(1);
	}
break;

beginstate 12;//find Horn of Jericho
	if ((get_skill_total(18) >= 25) && (get_flag(0,0) == 0)){
		reset_dialog_preset_options(1);
		add_dialog_str(0,"You place your hand on the wall. By chance, a secret compartment opens up. You find a brass horn with an engravement of a ruined city.",0);
		choice = run_dialog(0); 
		if (choice == 1)
			end();
		if (choice == 2){
			reward_give(450);
			set_flag(0,0,1);
			}
	}
break;

beginstate 13;//south gates
	reset_dialog_preset_options(8);
	choice = run_dialog(0);
	if (choice == 1)
		end();
	if (choice == 2) {
		play_sound(99);
		flip_terrain(8,44);
		flip_terrain(9,44);
	}
break;

beginstate 14;//north gates
	reset_dialog_preset_options(8);
	choice = run_dialog(0);
	if (choice == 1)
		end();
	if (choice == 2) {
		play_sound(99);
		flip_terrain(38,3);
		flip_terrain(39,3);
	}
break;

beginstate 15;//abandoned house
	if (get_flag(1,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"This house hasn't been lived in for a while. There are cobwebs and dust covering everything.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(1,0,1);
	}
break;

beginstate 16;//park
	if (get_flag(2,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"You enter a small memorial park. A statue of a large man holding a trumpet sits on top of a fountain in the middle of a pool.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(2,0,1);
	}
break;

beginstate 17;//council building
	if (get_flag(3,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"This is the town council building. It's rather small, considering the population, but the recent events of the valley have also flooded the town with migrants.",0);
		add_dialog_str(1,"There are two rows of seats on the floor, in front of a large podium. On the podium sit the three council representatives. The center one is beckoning you forward.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(3,0,1);
	}
break;

beginstate 18;//meeting room
	if (get_flag(4,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"This must be the room where the council holds confidential meetings. It doesn't look like it's been used very much.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(4,0,1);
	}
break;

beginstate 19;//Holmes' office
	if (get_flag(5,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"The only notable thing in this room is the man sitting at the desk. He's completely focused on the paper in front of him, writing on it as though it were about to escape. He pays no attention to you at all.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(5,0,1);
	}
break;

beginstate 20;//Key's office
	if (get_flag(6,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"This room is lined with shelves of papers. Probably a lot of town and valley records. Most likely nothing of interest to you.",0);
		add_dialog_str(1,"A friendly-looking man is working at the desk to your left. From here it's hard to tell exactly what he's working on. Probably something very important, most likely about the dragon.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(6,0,1);
	}
break;

beginstate 21;//Chris' room
	if (get_flag(7,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"This looks like a boy's room. However, there's no one in it right now, so it's hard to tell for sure.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(7,0,1);
	}
break;

beginstate 22;//Colleen and Becky's room
	if (get_flag(8,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"There are two teenage girls in this room. One is sitting at the table by the window, and the other is simply mulling about.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(8,0,1);
	}
break;